import { defineEventHandler, getCookie, createError } from 'h3';
import { BackupManager } from '../../utils/backup.js';

export default defineEventHandler(async (event) => {
  try {
    const userId = getCookie(event, 'userId');
    if (!userId) {
      throw createError({ statusCode: 401, statusMessage: 'Unauthorized' });
    }

    const backupManager = new BackupManager();
    const result = await backupManager.createBackup('manual');

    return {
      success: true,
      backup: result
    };
  } catch (error) {
    console.error('创建备份失败:', error);
    throw createError({ statusCode: 500, statusMessage: 'Failed to create backup' });
  }
});
